package com.tarena.lbs.config;

import com.tarena.lbs.repository.AttachFileRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.Date;

@Configuration
@EnableScheduling
public class ScheduledConfig {

    @Autowired
    private AttachFileRepository attachFileRepository;

    @Scheduled(cron = "0 0 1 * * ?")
    public void cleanExpiredFiles() {
        // 清理30天前的临时文件(status=0)
        Date expireDate = new Date(System.currentTimeMillis() - 30L * 24 * 60 * 60 * 1000);
        attachFileRepository.deleteExpiredFiles(expireDate);
    }
}
